﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;

namespace U9BJWebApi.Models
{



	public class SelectQuartzTaskInfoDTO
	{
		public string factoryId { get; set; }
		public string userNo { get; set; }
		public string workcenterId { get; set; }
		public string userToken { get; set; }
		public string accountSets { get; set; }
		public string dtoJsonStr { get; set; }
		public Int64 jobPkid { get; set; }
		public string jobId { get; set; }
	}


	public class RequestQuartzTaskHisInfoDto
	{
		public string factoryId { get; set; }
		public string userNo { get; set; }
		public string userPass { get; set; }
		public string workcenterId { get; set; }
		public Int32 stockType { get; set; }
		public string mlineId { get; set; }
		public string userToken { get; set; }
		public string accountSets { get; set; }
		public string dtoJsonStr { get; set; }
		public QuartzTaskInfoDTO quartzTaskInfoDTO { get; set; }
		public List<QuartzTaskLogInfoDto> quartzTaskLogInfoDto { get; set; }
	}

	public class QuartzTaskLogInfoDto
	{

		public Int64 jobPkid { get; set; }
		public string jobLog { get; set; }
		public string taskDate { get; set; }

	}
	public class QuartzTaskInfoDTO
	{

		public Int64 jobPkid { get; set; }
		public string jobId { get; set; }
		public Int64 taskPkid { get; set; }
		public string taskSequence { get; set; }
		public string jobMsg { get; set; }
		public string jobResult { get; set; }
		public int quartzStatus { get; set; }
		public string taskMsgId { get; set; }
	}

	public class PostHelper
	{
		public static SuccessRtn HttpPosts(string Url, string Json)
		{
			SuccessRtn rtn = new SuccessRtn();
			HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
			httpWebRequest.ContentType = "application/json";
			httpWebRequest.Method = "Post";
			httpWebRequest.Timeout = 20000;
			byte[] btBodys = Encoding.UTF8.GetBytes(Json);
			httpWebRequest.ContentLength = (long)btBodys.Length;
			httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);
			HttpWebResponse httpWebResponse;
			try
			{
				httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
			}
			catch (WebException ex)
			{
				httpWebResponse = (HttpWebResponse)ex.Response;
				rtn.rtnMsg = ex.Message;
				rtn.rtnSuccess = false;
			}
			bool flag = httpWebResponse != null;
			if (flag)
			{
				StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8);
				string responseContent = streamReader.ReadToEnd();
				rtn = JsonConvert.DeserializeObject<SuccessRtn>(responseContent);
				httpWebResponse.Close();
				streamReader.Close();
				httpWebRequest.Abort();
				httpWebResponse.Close();
			}
			else
			{
				rtn.rtnSuccess = false;
			}
			return rtn;
		}


		public static string HttpPost(string Url, string data)
		{
			
			HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
			httpWebRequest.ContentType = "text/xml";
			httpWebRequest.Method = "Post";
			httpWebRequest.Timeout = 20000;
			var encoding = Encoding.GetEncoding("utf-8");
			
			HttpWebResponse httpWebResponse;
			try
			{
				if (data != null)
				{
					byte[] buffer = encoding.GetBytes(data);
					httpWebRequest.ContentLength = buffer.Length;
					httpWebRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
				}
				httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
			}
			catch (WebException ex)
			{
				httpWebResponse = (HttpWebResponse)ex.Response;
				return ex.Message;
			}
			bool flag = httpWebResponse != null;
			if (flag)
			{
				StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8);
				string responseContent = streamReader.ReadToEnd();
			
				httpWebResponse.Close();
				streamReader.Close();
				httpWebRequest.Abort();
				httpWebResponse.Close();
				return responseContent;
			}
			else
			{
				return "";
			}

		}
	}

	public class SuccessRtn
	{
		public int rtnCode { get; set; }
		public bool rtnSuccess { get; set; }
		public string rtnMsg { get; set; }
		public int totalPage { get; set; }
		public string paging { get; set; }
		public int pageNo { get; set; }
		public int totalRecord { get; set; }
		public string dynamicDto { get; set; }

	}

	public class Result<T>
	{

		public int code { get; set; } = 1;


		public T data { get; set; }

		public string msg { get; set; } = "";
	}



	public class rtnMsg
	{
		public Int64 JobPkid { get; set; }
		public string JobId { get; set; }
		public Int64 TaskPkid { get; set; }
		public string TaskSequence { get; set; }
		public string JobMsg { get; set; }
		public string JobResult { get; set; }
		public int QuartzStatus { get; set; }
	}


	public class BasicDto
	{
		public string CreateMan { get; set; }
		public DateTime CreateDate { get; set; }
		public string EditMan { get; set; }
		public DateTime EditDate { get; set; }
		public string DelTag { get; set; } = "N";
		public string PubStr1 { get; set; }//客户编码
		public string PubStr2 { get; set; }//客户描述
		public string PubStr3 { get; set; }//认证型号
		public string PubStr4 { get; set; }//3C码
		public string PubStr5 { get; set; }//MES描述
		public int PubInt1 { get; set; }
		public int PubInt2 { get; set; }
		public int PubInt3 { get; set; }
		public int PubInt4 { get; set; }
		public int PubInt5 { get; set; }

	}
	public class IssueDocLineDTOHead
	{
		public long ID { get; set; }
		public List<IssueDocLineDTO> Body { get; set; }
	}


	public class IssueDocLineDTO : BasicDto
	{
		public string FactoryId { get; set; }
		public string Billno { get; set; }
		public string ProductionLineId { get; set; }
		public string MaterielId { get; set; }
		public string Barcode { get; set; }
		public decimal Qty { get; set; }
		public string Status { get; set; }
		public long Pkid { get; set; }
		public string TeamId { get; set; } //班组
		public string Remark { get; set; } 
	}


	public class ItemMasterDTO : BasicDto
	{
		public string FactoryId { get; set; }
		public string MaterielId { get; set; }
		public string MaterieName { get; set; }
		public string EnglishlName { get; set; }
		public string Mnemonic { get; set; }
		public string Drawingno { get; set; }
		public string Color { get; set; }
		public string Spec { get; set; }
		public string OldMaterielId { get; set; }
		public string MetricId { get; set; }
		public string MetricName { get; set; }
		public string Model { get; set; }
		public string StoreRoomId { get; set; }
		public string LocationId { get; set; }
		public string ManagerId { get; set; }
		public string ProductTypeId { get; set; }
		public string ProductTypeNames { get; set; }
		public string MaterielGroupId { get; set; }
		public string MaterielGroupName { get; set; }
		public decimal Length { get; set; }
		public decimal Width { get; set; }
		public decimal Height { get; set; }
		public decimal NetWeight { get; set; }
		public decimal Grossweight { get; set; }
		public DateTime Begindate { get; set; }
		public DateTime Enddate { get; set; }
		public string IsStockBatch { get; set; }
		public string IsSingle { get; set; }
		public decimal SecurityAmount { get; set; }
		public decimal MinAmount { get; set; }
		public decimal MaxAmount { get; set; }
		public string ABC { get; set; }
		public string IsValid { get; set; }
		public string ItemFormAttribute { get; set; }
		public long ERPPkid { get; set; }
	}

	public class BOMDTO : BasicDto
	{
		public string FactoryId { get; set; }
		public string MaterielId { get; set; }
		public string CopyRight { get; set; }
		public string BOMType { get; set; }
		public string ProductUOM { get; set; }
		public DateTime BeginDate { get; set; }
		public DateTime EndDate { get; set; }
		public string ERPPkid { get; set; }
		public List<BOMChild> BOMChilds { get; set; }
	}
	public class BOMChild : BasicDto
	{
		public int Sequence { get; set; }
		public string ChildMaterielId { get; set; }
		public string ChildMaterielName { get; set; }
		public string ProviderId { get; set; }
		public decimal Qty { get; set; }
		public string IsVaild { get; set; }
		public DateTime ChildBeginDate { get; set; }
		public DateTime ChildEndDate { get; set; }

	}

	public class MODTO : BasicDto
	{
		public string FactoryId { get; set; }
		public string Billno { get; set; }
		public string CustomerId { get; set; }
		public string SrcBillNo { get; set; }
		public int Sequence { get; set; }
		public string MaterielId { get; set; }
		public string CustomerMaterielId { get; set; }
		public decimal PlanQty { get; set; }
		public string LineId { get; set; }
		public DateTime RequireDate { get; set; }
		public DateTime BeginDate { get; set; }
		public DateTime EndDate { get; set; }
		public string StoreRoomId { get; set; }
		public string BomId { get; set; }
		public int SOSequence { get; set; }
		public string ProductionType { get; set; }
		public string ClassId { get; set; }
		public string MetricId { get; set; }
		public string ParentId { get; set; }
		public long ERPPkid { get; set; }
		public int Version { get; set; }
		public string BomVersion { get; set; }
		public string TeamId { get; set; }
		
		public List<MOPickListDTO> MOPickLists { get; set; }
	}
	public class MOPickListDTO : BasicDto
	{

		public string MaterielId { get; set; }

		public decimal ActualReqQty { get; set; }
	}
	public class SaleOutDTOHead
	{
		public long ID { get; set; }
		public List<SaleOutDTO> Body { get; set; }
	}

	public class SaleOutDTO : BasicDto
	{
		public string FactoryId { get; set; }
		public string Billno { get; set; }
		public string MESBillno { get; set; }
		//public int Sequence { get; set; }
		public string CustomerId { get; set; }
		public string ArcustomerId { get; set; }
		public string Materielid { get; set; }
		public string MetricId { get; set; }
		public decimal Qty { get; set; }
		public string Status { get; set; }
		public string StoreroomId { get; set; }
		public string BillType { get; set; }//类型  10调拨  20发运
		public string CarNO { get; set; }
		public string Remark { get; set; }
		public long Pkid { get; set; }
	}

	public class MESPullDTO : BasicDto
	{
		public string FactoryId { get; set; }
		public string RequireType { get; set; }
		public string MaterielId { get; set; }
		public string SupplierId { get; set; }
		public decimal RequireQty { get; set; }
		public string LineId { get; set; }
		public string Stockid { get; set; }
		public string WorkcenterId { get; set; }
		public string RequireDate { get; set; }
		public long Pkid { get; set; }
	}

	public class MESPullDTOHead
	{ 
		public  long ID { get; set; }
		public List<MESPullDTO> Body { get; set; }
	}

	public class TransDTOHead
	{
		public long ID { get; set; }
		public List<TransDTO> Body { get; set; }
	}

	public class TransDTO : BasicDto
	{
		public string FactoryId { get; set; }
		public string Billno { get; set; }
		public string MaterielId { get; set; }
		public string Barcode { get; set; }
		public decimal Qty { get; set; }
		public string Status { get; set; }
		public string TargetStatus { get; set; }
		public long Pkid { get; set; }
	}
	public class RequestQuartzTasksInfoDto
	{
		public string factoryId { get; set; }
		public string userNo { get; set; }
		public string workcenterId { get; set; }
		public string userToken { get; set; }
		public string accountSets { get; set; }
		public string dtoJsonStr { get; set; }
		public List<QuartzTaskInfoDTO> quartzTaskInfoDTOs { get; set; }
	}

	public class CallBackCommon
	{ 
		public int callBackType { get; set; }
		public List<CallBackInfo> callBackInfos { get; set; }
	}
	public class CallBackInfo 
	{ 
		public long Pkid { get; set; }
		public string ERPBillno { get; set; }
		public bool  IsSuccess { get; set; }
	}

	public class CallBackDTO
	{
		public long Pkid { get; set; }
		public string DocNo { get; set; }
		public int Status { get; set; }
		public string ErrorMessage { get; set; }
		public int Type { get; set; }
	}

	public class CallBack
	{
		public long Pkid { get; set; }
		public bool IsSuccess { get; set; }
		public string ErrorMessage { get; set; }
		public string Token { get; set; }

	}
	public class JobMsgDTO <T>
	{
		public long ERPPkid { get; set; }
		public List<T> JobMsg { get; set; }

	}
	public enum CallBackType
	{ 
		完工入库 = 10,
		产品合格与不合格调拨 = 20,
		销售出库凭证 = 30,
		序列拉动 = 40,
		循环拉动 = 50,
		计划拉动 = 60,
		看板拉动 = 70
	}
}